home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / culldir.c < prev    next >
C/C++ Source or Header  |  1994-11-16  |  2KB  |  75 lines

  1. /* this utility will make two passes over the current directory and
  2. ** the filedir.txt. The first pass will remove missing files from
  3. ** the entries, the second will add new ones.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. int parsename(char *, char *);
  9. int  main(int,char **);
  10. int  main(int argc,char **argv)
  11.   {
  12.   FILE *fopen(), *fd, *fo;
  13.   char line[8000], *fgets(), name[20];
  14.   printf("CULLDIR Extended V3.42\nCopyright (c) 1992 by Custom Services.\n");
  15.   if ((fd = fopen("filedir.txt", "r")) == NULL)
  16.     {
  17.     printf("Couldn't find a filedir.txt.");
  18.     return 10;
  19.     }
  20.   else
  21.     {
  22.     if ((fo = fopen("$tmp0000.dat", "w")) == NULL)
  23.       {
  24.       printf("Couldn't create temporary file");
  25.       return 10;
  26.       }
  27.     else
  28.       {
  29.       printf("...processing data\n");
  30.       while (fgets(line, 7998, fd) != NULL)
  31.         {
  32.         if (parsename(line, name))
  33.           {
  34.           if (access(name, 0) == 0)
  35.             {
  36.             fprintf(fo, "%s", line);
  37.  
  38.             }
  39.           else if (line[0] == ';') fprintf(fo, "%s", line);
  40.  
  41.           }
  42.         else if (line[0] == ';') fprintf(fo, "%s", line);
  43.  
  44.         }
  45.       fclose(fo);
  46.       }
  47.     fclose(fd);
  48.     unlink("filedir.txt");
  49.     rename("$tmp0000.dat", "filedir.txt");
  50.     }
  51.   return 0;
  52.   }
  53. parsename(src, target)
  54. char *src, *target;
  55.   {
  56.   char *strchr(), *space;
  57.   if ((space = strchr(src, ' ')) != NULL)
  58.     {
  59.     while (src != space)
  60.     *target++ = *src++;
  61.     *target = 0;
  62.     return 1;
  63.  
  64.     }
  65.   if (*src != ';')
  66.     {
  67.     strcpy(target, src);
  68.     if ((space = strchr(target, '\n')) != NULL) *space = 0;
  69.     return 1;
  70.  
  71.     }
  72.   return 0;
  73.  
  74.   }
  75.